package com.example.children.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.children.Model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


@Mapper
public interface UserMapper extends BaseMapper<User> {


    @Select("select * from User where id=#{id}")
    List<User> selectByUid(String id);


    @Select("SELECT COUNT(1) > 0 FROM User WHERE username = #{username}")
    boolean findByUsernameBool(String username);


    //通过名字查找用户
    @Select("SELECT * FROM User WHERE username = #{username}")
    User findByUsername(String username);

//密码验证
    @Select("SELECT * FROM User WHERE username = #{username} AND password = #{password}")
    User matches(User user);

    @Update("UPDATE User SET invitation_code = #{invitationCode} WHERE id = #{id}")
    void updateInvitationCode(User user);

    @Select("select id from User where invitation_code=#{invitationCode} and role='admin' ")
    String isInvitationCode(String invitationCode);

    @Select("SELECT count(1) > 0 FROM teacher WHERE id = #{id}")
    boolean isTeacherId(String id);


}
